#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int N = 2010;


void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int t1 = -1, t2 = -1;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'B' && t1 == -1){
            t1 = i;
        }
        if(s[i] == 'B'){
            t2 = i;
        }
    }
    if(t1 == -1){
        cout << 0 << endl;
        return;
    }
    cout << t2 - t1 + 1 << endl;
}

int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}